load("@com_github_johnynek_bazel_jar_jar//:jar_jar.bzl", "jar_jar")
load("//bazel:compat.bzl", "SKIP_ON_WINDOWS")
load("//sanitizers:sanitizers.bzl", "SANITIZER_CLASSES")

java_binary(
    name = "jazzer_agent_unshaded",
    create_executable = False,
    deploy_manifest_lines = [
        "Premain-Class: com.code_intelligence.jazzer.agent.Agent",
        "Jazzer-Hook-Classes: {}".format(":".join(SANITIZER_CLASSES)),
    ],
    runtime_deps = [
        "//agent/src/main/java/com/code_intelligence/jazzer/agent:agent_lib",
        "//sanitizers",
    ],
)

jar_jar(
    name = "jazzer_agent_deploy",
    input_jar = "jazzer_agent_unshaded_deploy.jar",
    rules = "agent_shade_rules",
    visibility = ["//visibility:public"],
)

sh_test(
    name = "jazzer_agent_shading_test",
    srcs = ["verify_shading.sh"],
    args = [
        "$(rootpath jazzer_agent_deploy.jar)",
    ],
    data = [
        # sh_test does not correctly forward runfiles associated to targets (such as
        # ":jazzer_agent_deploy"), so depend on a generated file instead.
        "jazzer_agent_deploy.jar",
        "@local_jdk//:bin/jar",
    ],
    target_compatible_with = SKIP_ON_WINDOWS,
)

java_binary(
    name = "jazzer_api",
    create_executable = False,
    visibility = ["//visibility:public"],
    runtime_deps = ["//agent/src/main/java/com/code_intelligence/jazzer/api"],
)

java_import(
    name = "jazzer_api_compile_only",
    jars = [
        ":jazzer_api_deploy.jar",
    ],
    neverlink = True,
    visibility = ["//visibility:public"],
    deps = [],
)
